package com.whu.waterworks.util;

import java.net.URI;
import java.net.URISyntaxException;

import com.whu.waterworks.mina.MyWebSocketClient;

public class MyWebSocketUtil {
	  private static MyWebSocketClient lazyHolder=null;  
	private MyWebSocketUtil() {
	}

	public static final MyWebSocketClient getInstance() throws URISyntaxException {
		if (lazyHolder==null || lazyHolder.getConnection().isClosed()==true) {
			lazyHolder=new MyWebSocketClient(new URI(
					"ws://127.0.0.1:2333"));
			lazyHolder.connect();
			while (lazyHolder.getConnection().isOpen() == false) {
				if (lazyHolder.getConnection().isOpen() == true) {
					break;
				}
			}
			return lazyHolder ;
		}
		else {
			return lazyHolder;
		}
	}
}
	
